import os
from urllib.parse import urlparse
from utils.tools import TushanCRUD
from components.log import log
from prisma import Prisma

# db = Database()
prisma = Prisma()

curd_service = TushanCRUD()



async def init_db():
    await prisma.connect()

    TushanCRUD.STATIC_TUSHAN_ADMIN_MAP["users"] = prisma.user
    TushanCRUD.STATIC_TUSHAN_ADMIN_MAP["competitions"] = prisma.competition
    TushanCRUD.STATIC_TUSHAN_ADMIN_MAP["competitionOrganizations"] = prisma.competition_organization
    TushanCRUD.STATIC_TUSHAN_ADMIN_MAP["dbs"] = prisma.datasource
    
    log.info("init db ok")


async def close_db():
    await prisma.disconnect()
    log.info("close_db ok")
